package com.chen.nio.zerocopy;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NewIOClient {
    public static void main(String[] args) throws Exception {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.connect(new InetSocketAddress("localhost", 8899));
        socketChannel.configureBlocking(true);
        String file = "D:\\baidu\\a.rar";
        FileChannel fileChannel = new FileInputStream(file).getChannel();
        long startTime = System.currentTimeMillis();
        long totalCount = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        System.out.println(totalCount);
        long endTime = System.currentTimeMillis();
        System.out.println("耗时：" + (endTime - startTime) + ",发送的总字节数：" + totalCount);

    }
}
